<template>
  <div class="login-panel">
    <h2 class="tip-word">后台管理系统</h2>
    <el-tabs type="border-card" class="demo-tabs" stretch>
      <el-tab-pane>
        <template #label>
          <span class="custom-tabs-label">
            <el-icon>
              <Avatar />
            </el-icon>
            <span>账号登录</span>
          </span>
        </template>
        <!-- ref绑定响应式对象 拿到的就是login-account组件对象 -->
        <login-account ref="accountRef" />
      </el-tab-pane>
      <el-tab-pane>
        <template #label>
          <span class="custom-tabs-label">
            <el-icon>
              <Iphone />
            </el-icon>
            <span>手机登录</span>
          </span>
        </template>
        <login-phone />
      </el-tab-pane>
    </el-tabs>
    <div class="account-control">
      <el-checkbox v-model="isKeepPasswords">记住密码</el-checkbox>
      <el-link type="primary">忘记密码</el-link>
    </div>
    <el-button type="primary" class="login-btn" @click="handleLoginClick">
      立即登录
    </el-button>
  </div>
</template>
<script lang="ts">
import { defineComponent, ref } from "vue";
import { Avatar } from "@element-plus/icons-vue";
import { Iphone } from "@element-plus/icons-vue";
import LoginAccount from "./login-account.vue";
import LoginPhone from "./login-phone.vue";
export default defineComponent({
  components: {
    Avatar,
    Iphone,
    LoginAccount,
    LoginPhone,
  },
  setup() {
    // 记录用户是否需要记住密码（就是有没有勾选记住密码选项）
    let isKeep = Boolean(localStorage.getItem("isKeepPassword") ?? false);
    const isKeepPasswords = ref(isKeep);

    // 定义响应式变量 需要类型 LoginAccount 对象类型
    const accountRef = ref<InstanceType<typeof LoginAccount>>();

    // 点击立即登录触发
    const handleLoginClick = () => {
      // accountRef.value 才能拿到对应的对象
      accountRef.value?.loginAction(isKeepPasswords.value);
    };

    return {
      isKeepPasswords,
      handleLoginClick,
      accountRef,
    };
  },
});
</script>
<style lang="less" scoped>
.login-panel {
  width: 320px;
  padding-bottom: 300px;
  .tip-word {
    text-align: center;
  }
  /* height: 100%; */
  .demo-tabs > .el-tabs__content {
    padding: 32px;
    color: #6b778c;
    font-size: 32px;
    font-weight: 600;
  }
  .demo-tabs .custom-tabs-label .el-icon {
    vertical-align: middle;
  }
  .demo-tabs .custom-tabs-label span {
    vertical-align: middle;
    margin-left: 4px;
  }
  .account-control {
    display: flex;
    justify-content: space-between;
    align-items: normal;
  }
  .login-btn {
    width: 100%;
  }
}
</style>
